package com.sun.designpatternsdemo.strategy

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import com.sun.designpatternsdemo.R
import com.sun.designpatternsdemo.app.AppConstant
import com.sun.designpatternsdemo.app.EMTagHandler
import com.sun.designpatternsdemo.base.BaseActivity
import com.sun.designpatternsdemo.databinding.ActivityStrategyBinding
import com.sun.designpatternsdemo.strategy.bean.*

/**
 * 策略模式（Strategy Pattern）：定义了算法族，分别封装起来，
 * 让它们之间可相互替换，此模式让算法的变化独立于使用算法的客户。
 */
class StrategyActivity : BaseActivity<ActivityStrategyBinding>() {

    override fun layoutId(): Int = R.layout.activity_strategy

    override fun initView(savedInstanceState: Bundle?) {
        title = "策略模式"
        mDataBind.apply {
            tvDefine.text = EMTagHandler.fromHtml(AppConstant.STRATEGY_DEFINE)
            btStrategyText.text = "创建角色A,并设定样子,攻击,逃跑,防御"
            btStrategyText.setOnClickListener {
                Toast.makeText(this@StrategyActivity, "123", Toast.LENGTH_SHORT).show()
                val role = RoleA("--A").apply {
                    setDisplay(DisplayYZ())
                        .setDefend(DefendTMS())
                        .setAttack(AttackXL())
                        .setRun(RunJCTQ())
                    display()// 样子
                    attack()// 攻击
                    run()// 逃跑
                    defend()// 防御
                }
            }
        }
    }
}